package com.hyh.shiyanshiguanli.service.impl;

import com.hyh.shiyanshiguanli.constant.MessageConstant;
import com.hyh.shiyanshiguanli.domain.dto.MessageDTO;
import com.hyh.shiyanshiguanli.domain.dto.StudentAddDTO;
import com.hyh.shiyanshiguanli.domain.dto.StudentUpdateDTO;
import com.hyh.shiyanshiguanli.domain.entity.Student;
import com.hyh.shiyanshiguanli.domain.vo.StudentVO;
import com.hyh.shiyanshiguanli.mapper.StudentMapper;
import com.hyh.shiyanshiguanli.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@Service
@SuppressWarnings({"ALL"})
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    public StudentVO page(MessageDTO messageDTO) {

      List<Student> students = studentMapper.page();
      int size = students.size();
        StudentVO studentVO = new StudentVO();
        studentVO.setTotal(size);
        studentVO.setStudents(students);
        return studentVO;
    }

    @Override
    public void add(StudentAddDTO studentAddDTO) {
        studentMapper.add(studentAddDTO);
    }

    @Override
    public Student selectById(Integer id) {
        return studentMapper.selectById(id);
    }

    @Override
    public void updateById(StudentUpdateDTO studentUpdateDTO) {
        studentMapper.updateById(studentUpdateDTO);
    }

    @Override
    public int deleteById(Integer id) {
        studentMapper.deleteById(id);
        return MessageConstant.SUCCESS;
    }
}
